package com.jade.yh.zsy.mobile.pay.api;

import com.jade.bss.base.RoleAction;
import com.jade.bss.base.utils.CopyBean;
import com.jade.framework.base.context.ApplicationContextUtils;
import com.jade.framework.base.util.PagingResult;
import com.jade.framework.base.util.ResponseUtils;
import com.jade.store.pay.entity.WithDraw;
import com.jade.store.pay.service.WithDrawFacade;
import com.jade.store.pay.vo.WithDrawVo;
import com.jade.zsy.base.common.ParametersException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;

/**
 * Created with IntelliJ IDEA.
 * User: jinya
 * Date: 2017/6/23
 * Time: 23:38
 * TEL :17701640710   MAIL:2009_jinya@163.com
 * To change this template use File | Settings | File Templates.
 */
@RestController
@RequestMapping(value = "/withDraw", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(value = "交易流水", description = "财务模块--交易流水")
public class WithDrawApi {
    private WithDrawFacade withDrawFacade = ApplicationContextUtils.getBean("WithDrawFacade");
    @RequestMapping(value =  RoleAction.QUERY, method = RequestMethod.GET)
    @ApiOperation(value = "交易清单", httpMethod = "GET", response = WithDrawVo.class)
    public void QUERY(@ApiParam(value = "起始值") @RequestParam(value = "offset", defaultValue = "0") int offset,
                      @ApiParam(value = "每页大小") @RequestParam(value = "length", defaultValue = "10") int length,
                      @ApiParam(value = "关键词") @RequestParam (value = "keyword", required = false) String keyword,
                      @ApiParam(value = "排序字段") @RequestParam(value = "sort", required = false) String sort,
                      @ApiParam(value = "排序规则", allowableValues = "desc, asc") @RequestParam(value = "order", required = false) String order,
                      HttpServletResponse response, WithDrawVo entityVo) throws Exception {
        PagingResult result = withDrawFacade.queryEntity(entityVo, offset, length, keyword, sort);
        ResponseUtils.writeSuccessPagingResult(response, result);
    }
    @ApiOperation(value = "交易详情")
    @RequestMapping(value =  RoleAction.GET, method = RequestMethod.GET)
    public void GET(@ApiParam(value = "键值") @RequestParam(value = "id", defaultValue = "0") long id,HttpServletResponse response)throws Exception{
        WithDraw entity = withDrawFacade.getById(WithDraw.class, id);
        if (null == entity) {
            throw new ParametersException("err.module.record.not_existed", "record not existed");
        }
        WithDrawVo vo = CopyBean.copy(entity, WithDrawVo.class);
        ResponseUtils.writeSuccessResult(response, vo);
    }
}
